package com.bibrApp.difu.actvity.recharge_b_mvp;

import android.content.Context;

import com.bibrApp.difu.Response.RechargeAddressData;
import com.bibrApp.difu.api.RetrofitNet;
import com.bibrApp.difu.base.BaseObserver;
import com.bibrApp.difu.base.BasePresenter;
import com.bibrApp.difu.utils.EncryptUtils;
import com.google.gson.Gson;

import java.util.HashMap;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class RechargeBPresenter extends BasePresenter<IRechargeBView> {
    public RechargeBPresenter(Context context, IRechargeBView iView) {
        super(context, iView);
    }

    public void getRechargeAddressP(String bName , String userId) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("coinCode",bName);
            RetrofitNet.getInstance().getApi()
                    .getRechargeAddress(EncryptUtils.encrypt(map))
                    .compose(getActivityLifecycleProvider().bindToLifecycle())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribeOn(Schedulers.io())
                    .subscribe(new BaseObserver<Object>(context) {
                        @Override
                        protected void onSuccess(Object value) {
                            String jsonStr = EncryptUtils.objectToJson(value);
                            RechargeAddressData rechargeAddressData = new Gson().fromJson(jsonStr, RechargeAddressData.class);
                            iView.success(rechargeAddressData);
                        }

                        @Override
                        protected void onFialure(int code, String msg) {
                            super.onFialure(code, msg);
                        }
                    });
    }

}
